package com.LeeCode;

import java.util.HashMap;

/**
 * 随机链表的复制
 */

public class Code138 {
    public static void main(String[] args) {

    }

    public Node copyRandomList(Node head) {

        HashMap<Node, Node> map = new HashMap<>();
        Node cur = head;
        while (cur != null) {
            map.put(cur, new Node(cur.val));
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }
}
